package com.googlecode.websword.rest.test;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.googlecode.websword.rest.annotation.Param;
import com.googlecode.websword.rest.annotation.ParamValue;
import com.googlecode.websword.rest.annotation.Rest;
import com.googlecode.websword.rest.annotation.RestSupport;
import com.googlecode.websword.rest.service.convert.RestRequestParamParse;

@Component
@RestSupport
public class RestBean {
    @Rest(url = "sayhi")
    public String sayHello(String name) {
        // http://localhost/rest/sayhi/websword
        return "Hi, " + name;
    }
    
    @Rest(url = "get")
    public Map<String, Object> map(long age) {
        // http://localhost/rest/get/12
        Map<String, Object> m = new HashMap<String, Object>();
        m.put("age", age);
        m.put("hi", "hello");
        return m;
    }
    
    @Rest(url = "echo")
    public String echo(String name) {// http://localhost/rest/echo/testname
        return name;
    }
    
    @Rest(url = "param", parse = RestRequestParamParse.class)
    public Map<String, Object> param(@Param(name = "name") @ParamValue(value = "websword") String name) {
        // http://localhost/rest/param/?name=testsword
        Map<String, Object> m = new HashMap<String, Object>();
        m.put("age", 12);
        m.put("name", name);
        return m;
    }
}
